package example;

import example.com.terry.utils.JDBCUtils;

import javax.servlet.*;
import java.io.IOException;
import java.sql.ResultSet;

//@WebServlet("/tests")
public class Login implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        //初始化第一个执行
        System.out.println(1);
    }
    @Override
    public ServletConfig getServletConfig() {
        System.out.println(1);
        return null;
    }
    @Override
    public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException {
        //业务方法
        System.out.println(1);
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        boolean init = JDBCUtils.init("update student set password = '" + password + "',name = '" + username + "' where id = 1 ");
        ResultSet resultSet = JDBCUtils.initQuery("select * from student");

        try {
            if (resultSet.next()) {

                System.out.println(1);
                String password1 = resultSet.getString("password");
            }
        } catch (Exception e
        ) {

        }
        JDBCUtils.destroy();
        //转发页面
        req.getRequestDispatcher("WEB-INF/jsp/login.jsp").forward(req, resp);
    }

    @Override
    public String getServletInfo() {
        System.out.println(1);
        return null;
    }

    @Override
    public void destroy() {
        System.out.println(1);

    }
}
